﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Content/Master.Master" Inherits="System.Web.Mvc.ViewPage<SCS.Core.ViewModels.DiscountManageViewModels>" %>
<%@ Import Namespace="SCS.Core" %>
<%@ Import Namespace="SCS.Core.Models" %>
<%@ Import Namespace="SCS.Core.ViewModels" %>
<%@ Import Namespace="SCS.Core.Controllers" %>
<%@ Import Namespace="SCSService" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	DiscountManage
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

    <script type="text/javascript">
        $(function () {
            $("#StartDateSearch").datepicker();
            $("#EndDateSearch").datepicker();
        });
	</script>
    <script type="text/javascript">
        function SaveStatus(dropDownList, id) {
            var selectedReport = dropDownList.options[dropDownList.selectedIndex];
            var selects = selectedReport.value;
            actionChangeStatus(selects, id);
        }
        function actionChangeStatus(values, id) {
            var url = '<%=Url.Action("ChangeStatusDiscount","Stock")%>' + '/' + id + '/' + values;
            $.getJSON(url, function (outStr) {
                $('#statusID' + id).val(outStr);
            });
        }
     </script>
      <% using (Html.BeginForm("DiscountManage", "Stock", FormMethod.Post, new { id = "sendFileForm", enctype = "multipart/form-data" }))
   {%>
    <div class="clear"></div>
    <div class="column full">
    <div class="box ">
        
		<h2 class="box-header">	Quản lý khuyến mãi <% if (Model.Product != null) { var nameProduct = Model.Product.ProductName; Response.Write(nameProduct); } %> </h2>
		<div class="box-content">

                    <div id="grid">	
                                <div style="float:right; margin:10px;"> 
                                   <%= Html.ActionLink("Thêm mới", "CreateDiscount", null, new { @Class = "button themed" })%>
                                </div>			    						               
				                <table class="display" id="tabledata" >
                                <thead>
					                <tr>
						                <th>
                                            <a href="#" class="<%= StockController.GetGridThClass(ViewData, "TypeDiscounts") %>" 
										                onclick="<%= StockController.GetGridThOnClick(ViewData, "TypeDiscounts")%>">
								              Kiểu giám giá</a>
                                        </th>
                                        
                                        <th>
                                            <a href="#" class="<%= StockController.GetGridThClass(ViewData, "DiscountPercent") %>" 
										                onclick="<%= StockController.GetGridThOnClick(ViewData, "DiscountPercent")%>">
								                Phần trăm</a>
                                        </th>
                                        
                                        <th>
                                            <a href="#" class="<%= StockController.GetGridThClass(ViewData, "DiscountValue") %>" 
										                onclick="<%= StockController.GetGridThOnClick(ViewData, "DiscountValue")%>">
								                Giá trị</a>
                                        </th>	
                                        				               
						                <th>
							                <a href="#" class="<%= StockController.GetGridThClass(ViewData, "StartDate") %>" 
										                onclick="<%= StockController.GetGridThOnClick(ViewData, "StartDate")%>">
								                Ngày bắt đầu</a>
						                </th>
						
						                <th>
							                <a href="#" class="<%= StockController.GetGridThClass(ViewData, "EndDate") %>" 
										                onclick="<%= StockController.GetGridThOnClick(ViewData, "EndDate")%>">
								                Ngày kết thúc</a>
						                </th>											                

                                        <th>
                                            <a href="#" class="<%= StockController.GetGridThClass(ViewData, "Satus") %>" 
										                onclick="<%= StockController.GetGridThOnClick(ViewData, "Satus")%>">
								                Trạng thái</a>
                                        </th>
                                        <th>Sửa</th>
                                        <th>Xóa</th>                                       
					                </tr>
                                   <%-- <tr>
                                        <td></td>
                                        <td></td>
                                        <td></td>
                                        <td></td>
                                        <td></td>
                                        <td></td>
                                        <td></td>
                                        <td>
                                             <%= Html.ActionLink("Thêm mới", "CreateDiscount", null, new { @Class = "button themed" })%>
                                        </td>
                                    </tr>--%>
                                    <tr>
                                        <td>
                                            <%
                                                List<SelectListItem> typeDiscountSearch = new List<SelectListItem>();
                                                typeDiscountSearch.AddRange(new SelectListItem[] { 
                                                new SelectListItem{ Text = "All", Value = "-1"},
                                                new SelectListItem{ Text = "Percent", Value = "1" },
                                                new SelectListItem{ Text = "value", Value = "0" }
                                                
                                                });
                                                %>

                                                <%=Html.DropDownListFor(m => m.TypeDiscounts, typeDiscountSearch)%> 
                                        </td>

                                        <td colspan="2">
                                            <%=Html.TextBoxFor(m => m.ValueSearch, new { @class = "form-field hafl", @maxlength = "50" })%>
                                        </td>
                                        
                                        <td>
                                            Ngày bắt đầu: <%=Html.TextBoxFor(m=>m.StartDateSearch,new { @class = "form-field datepicker"}) %>
                                        </td>
                                        <td>
                                            Đến ngày: <%=Html.TextBoxFor(m=>m.EndDateSearch,new { @class = "form-field datepicker"}) %>
                                        </td>
                                        <td>
                                            <%
                                                List<SelectListItem> statusSearch = new List<SelectListItem>();
                                                statusSearch.AddRange(new SelectListItem[] { 
                                                new SelectListItem{ Text = "Kích hoạt", Value = "1" },
                                                new SelectListItem{ Text = "Không kích hoạt", Value = "0" }
                                                });
                                                %>

                                                <%=Html.DropDownListFor(m => m.StatusSearch, statusSearch)%> 
                                        </td>
                                        <td></td>
                                        <td>
                                            <input type="submit" value="Search" class="button themed"/>
                                        </td>
                                    </tr>
                                </thead>
                                <% if (Model.DiscountList.Count() == 0)
                                   { %>
			                        <tbody>
                                        <tr>
                                            <td colspan="9">
                                                Không có chương trình khuyến mãi.
                                            </td>
                                        </tr>
                                    </tbody>
		                        <% } else { %>
                                <tbody>
					                <% foreach (var item in Model.DiscountList) { %>
				    
						                <tr>						                
							                <td>
								                <%
                                                    bool typeDiscount=false;
                                                    typeDiscount=(bool)item.TypeDiscounts;
                                                %>
                                                <%
                                                List<SelectListItem> typeDiscountDrop = new List<SelectListItem>();
                                                typeDiscountDrop.AddRange(new SelectListItem[] { 
                                                new SelectListItem{Selected=typeDiscount, Text = "Percent", Value = "1" },
                                                new SelectListItem{Selected=typeDiscount, Text = "Value", Value = "0" }
                                                });
                                                %>
                                              
                                               <%= Html.DropDownList("TypeDiscounts" + item.DiscountsID, typeDiscountDrop, new { onchange = "SaveStatus(this," + item.DiscountsID + ")" })%>
							                </td>
							
                                            <td>
                                                <%= Html.Encode(item.DiscountPercent) %>
                                            </td>

                                            <td>
                                                <%= Html.Encode(item.DiscountValue) %>
                                            </td>

							                <td>
								                <%= Html.Encode(item.StartDate) %>
							                </td>
														                
                                            <td>
                                               <%= Html.Encode(item.EndDate) %>
                                            </td>
                                            
                                            <td>
                                               <%
                                                    bool newStatus=false;
                                                    if (item.Status == 0)
                                                    {
                                                        newStatus=true;
                                                    }
                                                    else if (item.Status == 1)
                                                    {
                                                        newStatus=false;
                                                    }
                                                %>
                                                <%
                                                List<SelectListItem> statusDrop = new List<SelectListItem>();
                                                statusDrop.AddRange(new SelectListItem[] { 
                                                new SelectListItem{Selected=newStatus, Text = "Kích hoạt", Value = "1" },
                                                new SelectListItem{Selected=newStatus, Text = "Không kích hoạt", Value = "0" }
                                                });
                                                %>
                                              
                                               <%= Html.DropDownList("statusID" + item.DiscountsID, statusDrop, new { onchange = "SaveStatus(this," + item.DiscountsID + ")" })%>
                                            </td>
                                            <td>
                                                <%--<%= Html.ActionLink("Sửa", "EditDiscount", new { id = item.DiscountsID })%>--%>
                                                 <span class="button white"> <%= Html.ActionLink(" ", "EditDiscount", new { id = item.DiscountsID }, new { @class = "icon_single edit", style = "color:#f7a468;" })%></span>	<!--cap nhat-->
                                            </td>
                                            <td>
                                                <%
                                                    string returnUrl = Request.Url.ToString();
                                                 %>
                                               <%-- <%= Html.ActionLink("Xóa", "DeleteDiscount", new { id = item.DiscountsID, returnUrl = returnUrl }, new { onclick = "return confirm('Delete Discount:" + (item.TypeDiscounts == true ? item.DiscountPercent : item.DiscountValue).ToString() + " ?');" })%>--%>
                                                <span class="button white"><%= Html.ActionLink(" ", "DeleteDiscount", new { id = item.DiscountsID, returnUrl = returnUrl }, new { @class = "icon_single cancel", style = "color:#cc0000;", onclick = "return confirm('Bạn thực sự muốn xóa?');" })%></span>
                                            </td>
						                </tr>
				    
					                <% } %>
					            </tbody>
                                <% } %>
				                </table>
			                <!-- data -->
                                <%--<% if (Model.DiscountList.Count() > 0)
                                   { %>
			                       <% Html.RenderPartial("~/Views/Commont/Paging.ascx"); %>
		                        <% } %>--%>
		                
	                </div>  <!-- grid -->	
                
               
	    </div>
	</div>
    <div class="clear"></div>
    </div>    
<% } %>
</asp:Content>
